import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/app/modules/component/component_page.dart';
import 'package:my_app/app/modules/home/home_controller.dart';
import 'package:my_app/app/modules/template/template_page.dart';
import 'package:my_app/app/modules/tool/tool_page.dart';

/// home_page.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description:首页
///
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final HomeController myController = Get.put(HomeController());

    final PageController pageController =
        PageController(initialPage: myController.index.value);
    return Scaffold(
      body: PageView(
        controller: pageController,
        physics: NeverScrollableScrollPhysics(), // 禁止滑动
        children: [ComponentPage(), ToolPage(), TemplatePage()],
      ),
      bottomNavigationBar: Obx(() => BottomNavigationBar(
            items: <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                  icon: Icon(Icons.widgets_outlined), label: "组件"),
              BottomNavigationBarItem(
                  icon: Icon(Icons.settings_outlined), label: "工具"),
              BottomNavigationBarItem(
                  icon: Icon(Icons.dashboard_outlined), label: "模板"),
            ],
            currentIndex: myController.index.value,
            onTap: (index) {
              myController.changeIndex(index);
              pageController.jumpToPage(index);
            },
          )),
    );
  }
}
